Ext.define('BEST.controller.RoleoperController',
				{
					extend : 'Ext.app.Controller',
					views : [ 'roleoper.Layout', 'roleoper.Tree', 'roleoper.List',
							'roleoper.Edit'],
					stores : ['RoleStore'],
					models : ['RoleModel'],
					refs : [/*{
						ref : 'addBtn',
						selector : 'roleoperlist button#add'
					}, */{
						ref : 'editBtn',
						selector : 'roleoperlist button#edit'
					}/*, {
						ref : 'delBtn',
						selector : 'roleoperlist button#delete'
					}, {
						ref : 'stateBtn',
						selector : 'roleoperlist button#state'
					}, {
						ref : 'detailBtn',
						selector : 'roleoperlist button#detail'
					}*/, {
						ref : 'saveBtn',
						selector : 'roleoperedit button#save'
					}, {
						ref : 'cancelBtn',
						selector : 'roleoperedit button#cancle'
					} ],
					init : function() {
						var me=this;
						this.control({
							'roleopertree' : {
								afterrender : function(obj) {
									
								}
							},
							'roleoperlist' : {
								select : this.onSelect,
								deselect : this.onDeselect
							},
							/*'roleoperlist button#add' : {
								click : this.onAdd
							},*/

							'roleoperlist button#edit' : {
								click : this.onEdit
							},
							/*'roleoperlist button#detail' : {
								click : this.onDetail
							},
							'roleoperlist button#delete' : {
								click : this.onDelete
							},
							'roleoperedit#editmap' : {
								afterrender : function(component, eOpts) {
									
								}
							},*/
							'roleoperedit button#save' : {
								click : this.onSave
							},
							'roleoperedit button#cancle' : {
								click : this.onClose
							}/*,
							'roleoperdetail button#detail-close' : {
								click : this.onClose
							}*/
						});
					},
					onSelect : function(_that, rec) {
						this.changeBtnState(false);
						var curTsrId=rec.get('tsrId');
						Ext.getCmp('roleopertree').getStore().load({
							  params: {
							    "tsrId": curTsrId
							  }
							});
						Ext.getCmp('roleopertree').getView().refresh();
					
					
					},
					onDeselect : function() {
						this.changeBtnState(true);
					},
					onAdd : function(btn) {
						Ext.widget('roleoperedit', {
							animateTarget : document.body,
							title : btn.getText()
						}).show();
					},

					onEdit : function(btn) {
						var win = Ext.widget('roleoperedit', {
							animateTarget : document.body,
							title : btn.getText()
						});
						var record = btn.up('roleoperlist').getSelectionModel()
								.getLastSelected();
						win.down('form').getForm().loadRecord(record);
						win.show();
					},
					/*onDelete : function(btn) {
						var me = this;
						Ext.MessageBox.confirm('确认信息', '确认删除该记录吗?', function(
								_btn) {
							if (_btn == 'yes') {
								var record = btn.up('roleoperlist')
										.getSelectionModel().getLastSelected();
								btn.up('roleoperlist').getStore().remove(record);

							}
						});
					},*/
					/*onDetail : function(btn) {
						this.showWin('roleoperdetail', btn);
					},*/
					
					onSave : function(btn) {
						var me = this;
						var win = btn.up('window');
						var form = win.down('form').getForm();
						var treeCheckRecords=win.getComponent('edittree').getView().getChecked();
						var arrayCheckRecords=[];
						Ext.Array.each(treeCheckRecords, function(rec){
							arrayCheckRecords.push(rec.get('id'));
				        });
						var opers=arrayCheckRecords.join();
						
						if (form.isValid()) {
							var tsrId = form.getRecord().get('tsrId');
							Ext.Ajax.request({
								method:'POST',//提交的方式,如Get，post等
								url:mainServer+'/roleoper/save',//请求地址
								params:{ 'tsrId':tsrId,'tmroIds':opers},
					            success:function(reps,option){
					             var repsObj=Ext.JSON.decode(reps.responseText);//此为后台成功返回的json等字符
					             if(repsObj['success']){
					            	 //console.info(win.getComponent('edittree'));
					            	 Ext.getCmp('roleopertree').getStore().load({
										  params: {
										    "tsrId": tsrId
										  }
										});
									Ext.getCmp('roleopertree').getView().refresh();
					            	 //console.info(Ext.widget('roleopertree').getStore());
					            	//Ext.getCmp('edittree').getStore().reload();
					            	/* Ext.getStore('RoleStore').sync();
										Ext.getStore('RoleStore').reload();*/
										Ext.example.msg('温馨提示', '状态修改成功');
					             }
					            },//成功的回调函数    
					            failure:function(res){
					      
					            }//失败的情况
							});
							win.close();
						}
					},
					onClose : function(btn) {
						btn.up('window').close();
					},
					changeBtnState : function(state) {
						this.getEditBtn().setDisabled(state);
						/*this.getDelBtn().setDisabled(state);
						this.getStateBtn().setDisabled(state);
						this.getDetailBtn().setDisabled(state);*/
					},
					showWin : function(winName, btn) {
						var win = Ext.widget(winName, {
							animateTarget : document.body,
							title : btn.getText()
						});
						var record = btn.up('roleoperlist').getSelectionModel()
								.getLastSelected();
						win.down('form').getForm().loadRecord(record);
						win.show();
					},
					showResult : function() {
						Ext.example.msg('温馨提示', msg);
					}

				});